<template>
	<view class="container">
		<view class="tab space-between" v-if="userInfo.jobId != 3 && show">
			<view class="tab-text" :class="{'active': !level}" @click="changeTab('')">全部</view>
			<view class="tab-text" :class="{'active': level == 1}"  @click="changeTab(1)">我的</view>
			<view class="tab-text" :class="{'active': level == 4}"  @click="changeTab(4)">其他</view>
		</view>
		<view class="use-box">
			<view class="use-item">
				<view class="use-list space-between" v-for="(item,index) in dataList" :key="index">
					<view class="left">
						<view class="text">{{item.level == 1 ? '我的' : '其他'}}</view>
						<view class="time">支付时间：{{item.createTime}}</view>
					</view>
					<view class="money">+{{item.price}}</view>
				</view>
			</view>
		</view>
		<view class="no-data" v-if="!dataList.length">暂无数据</view>
		<view class="no-data" v-if="noMore">没有更多了</view>
	</view>
</template>

<script>
	import {
		getProfitList,
		getUserInfo
	} from '../../api/active'
	import {
		getTimeBytimeStamp
	} from '../../utils/plug.js'
	export default {
		data() {
			return {
				size: 20,
				show: false,
				current: 1,
				noMore: false,
				dataList: [],
				level: "",
				userInfo: {}
			}
		},
		onLoad() {
			this.getInfo()
			this.getData()
		},
		methods: {
			changeTab(num) {
				this.level = num
				this.current = 1
				this.noMore = false;
				this.getData()
			},
			getInfo() {
				getUserInfo({
						userId: uni.getStorageSync("userId")
					})
					.then(res => {
						this.userInfo = res.data
					})
			},
			getData() {
				uni.showLoading({
					title: "加载中..."
				})
				getProfitList({
						userId: uni.getStorageSync("userId"),
						size: this.size,
						current: this.current,
						level: this.level
					})
					.then(res => {
						this.show = true;
						uni.hideLoading()
						uni.stopPullDownRefresh()
						if (this.current == 1) {
							this.dataList = res.data.records
						} else {
							this.dataList = [...this.dataList, ...res.data.records]
						}
						if (res.data.records.length) {
							this.dataList.forEach(item => {
								item.createTime = getTimeBytimeStamp(item.createTime)
							})
							if (res.data.total > this.current * this.size) {
								this.noMore = false
								this.current++
							} else {
								this.noMore = true;
							}
						}
					})
					.catch(() => {
						uni.hideLoading()
						uni.stopPullDownRefresh()
					})
			},
		},
		onPullDownRefresh() {
			this.current = 1
			this.noMore = false;
			this.getData()
		},
		onReachBottom() {
			if (!this.noMore) {
				this.getData()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tab {
		height: 80rpx;
		width: 100%;
		background: #fff;
		align-items: center;
		padding: 0 90rpx;

		.tab-text {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			position: relative;

			&.active {
				font-family: PingFang SC;
				font-weight: 800;
				font-size: 36rpx;
				color: #005097;
				border-radius: 5rpx;

				&::after {
					content: '';
					position: absolute;
					display: block;
					bottom: -15rpx;
					left: 14rpx;
					width: 35rpx;
					height: 9rpx;
					background: #005097;
					border-radius: 5rpx;
				}
			}
		}
	}

	.no-data {
		font-weight: 500;
		font-size: 26rpx;
		color: #999999;
		text-align: center;
		padding-top: 20rpx;
	}

	.container {
		width: 100vw;
		min-height: 100vh;
		background: #f5f5f5;
		padding-bottom: 20rpx;
	}

	.use-box {
		display: flex;
		flex-direction: column;
		margin-top: 20rpx;
	}

	.use-item {
		width: 100%;
		background: #ffffff;
		padding: 0 40rpx;
	}

	.use-list {
		align-items: center;
		border-bottom: 2rpx solid #F1F1F1;
		height: 140rpx;

		.text {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #333333;
		}

		.time {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #999999;
			margin-top: 15rpx;
		}

		.money {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #DC1010;
		}

		&:last-child {
			border-bottom: none;
		}
	}
</style>